package animation;

import java.util.ArrayList;

/**
 * An instance of an animation linked up to a skeleton.
 */
public class AnimationInstance {
	// throws InvalidArgumentException if animation doesn't line up with skeleton
	public AnimationInstance(Animation animation, Skeleton skeleton) {
		if (animation == null || skeleton == null) {
			throw new IllegalArgumentException("Animation or skeleton not specified");
		}
		this.animation = animation;
		this.skeleton = skeleton;
		animatedBoneIndices = new ArrayList<Integer>();
		for (int i = 0; i < animation.getAnimatedBoneCount(); ++i) {
			Animation.AnimatedBone animatedBone = animation.getAnimatedBone(i);
			int bone = skeleton.getBoneIndex(animatedBone.getBoneName());
			if (bone < 0) {
				throw new IllegalArgumentException("Animation and skeleton are not compatible: " +
						"bone " + animatedBone.getBoneName() + " not found in skeleton");
			} else
				animatedBoneIndices.add(bone);
		}
	}

	public Animation getAnimation() {
		return animation;
	}

	public Skeleton getSkeleton() {
		return skeleton;
	}

	// returns the bone index of the ith animated bone in the animation
	public int getAnimatedBoneIndex(int i) {
		return animatedBoneIndices.get(i);
	}

	private Animation animation;
	private Skeleton skeleton;

	// indices in skeleton of each animated bone in animation
	private ArrayList<Integer> animatedBoneIndices;
}
